#include "summaryRanges.h"
std::vector<std::string> summaryRanges(std::vector<int> &nums) {
    std::vector<std::string> result;
    const int n = nums.size();
    if (n == 0)
        return result;
    if (n == 1) {
        result.emplace_back(std::to_string(nums[0]));
        return result;
    }

    int left = 0;
    int right = 0;
    int current = 0;

    while (right < n) {
        current = nums[left];
        while (right + 1 < n && nums[right + 1] == current + 1) {
            current = nums[right + 1];
            right++;
        }
        if (left == right)
            result.push_back(std::to_string(current));
        else
            result.push_back(std::to_string(nums[left]) + std::string("->") +
                             std::to_string(current));
        right++;
        left = right;
    }
    return result;
}
